#include <iostream>

class Complex
{
public:
    Complex():real(0),vir(0){};
    Complex(int real,int vir):real(real),vir(vir){};
    Complex(const Complex& c){std::cout<<"拷贝构造函数"<<std::endl;this->vir = c.vir; this->real = c.real;}
    ~Complex(){}
    friend std::ostream& operator<<(std::ostream &os,const Complex &c);
    friend std::istream& operator>>(std::istream &is,Complex& c);
    
    Complex operator+(const Complex& c)
    {
        Complex result;
        result.real = this->real + c.real;
        result.vir = this->vir + c.vir;
        return result;
    }
    Complex operator-(const Complex& c)
    {
        Complex result;
        result.real = this->real - c.real;
        result.vir = this->vir - c.vir;
        return result;
    }
    //前置++
    Complex& operator++()
    {
        this->real++;
        this->vir++;
        return *this;
    }
    //后置++
    Complex operator++(int)//占位符：既不要参数，又能构成重载
    {
        Complex temp = *this;
        this->real++;
        this->vir++;
        return temp;
    }

private:
    int real;//实部
    int vir;//虚部
};

std::ostream& operator<<(std::ostream &os,const Complex &c)//输出流对象
{
    if(c.vir < 0)
    {
        if(c.vir == -1)
            os<<c.real<<"-i";
        else
            os<<c.real<<c.vir<<"i";
    }
    else
    {
        if(c.vir == 1)
            os<<c.real<<"+i";
        else
            os<<c.real<<"+"<<c.vir<<"i";
    }
    return os;   
}
std::istream& operator>>(std::istream &is,Complex& c)
{
    is>>c.real>>c.vir;
    return is;
}


int main()
{
    Complex c1(1,2);
    // Complex c2 = c1;
    ++c1;
    std::cout<<c1<<std::endl;
    // Complex c3 = c1 + c2; //->c1.operator+(c2)——运算符的重载本质上是函数调用
    // std::cin>>c3;
    // std::cout<<c3<<std::endl;

    return 0;
}